
package guice.boot.archive.spi.model;

import guice.boot.archive.spi.registry.ServiceFilter;
import guice.boot.archive.spi.registry.ServiceReference;

import java.util.List;
import java.util.Set;


public interface PluginRuntimeContext {

    /**
     * get Plugin
     *
     * @return plugin
     */
    Plugin getPlugin();

    /**
     * get Plugin by Plugin Name
     *
     * @param pluginName plugin name
     * @return plugin
     */
    Plugin getPlugin(String pluginName);

    /**
     * get All Plugin Names
     *
     * @return
     */
    Set<String> getPluginNames();

    /**
     * get Plugin ClassLoader
     *
     * @return plugin classloader
     */
    ClassLoader getClassLoader();

    /**
     * Publish Plugin Service
     *
     * @param ifClass    service interface
     * @param implObject service implement object
     * @param <T>
     * @return
     */
    <T> ServiceReference<T> publishService(Class<T> ifClass, T implObject);

    /**
     * Publish Plugin Service
     *
     * @param ifClass    service interface
     * @param implObject service implement object
     * @param uniqueId   service implementation id
     * @param <T>
     * @return
     */
    <T> ServiceReference<T> publishService(Class<T> ifClass, T implObject, String uniqueId);

    /**
     * Get Service publish by plugin, when there are multiple services, return the highest priority plugin service
     *
     * @param ifClass service interface
     * @param <T>
     * @return service reference
     */
    <T> ServiceReference<T> referenceService(Class<T> ifClass);

    /**
     * Get Service publish  by one specific plugin
     *
     * @param ifClass  service interface
     * @param <T>
     * @param uniqueId service implementation
     * @return service reference
     */
    <T> ServiceReference<T> referenceService(Class<T> ifClass, String uniqueId);

    /**
     * Get Service List publish by plugin
     *
     * @param serviceFilter service filter
     * @return
     */
    List<ServiceReference> referenceServices(ServiceFilter serviceFilter);

}